package com.zwj.Interceptor;

import com.zwj.utils.Constants;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor extends HandlerInterceptorAdapter{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获取Session中的变量，判断用户是否登录
        HttpSession session = request.getSession();
        Object o = session.getAttribute(Constants.USER_SESSION);
        if (o != null) {
            return true;
        } else {
//            response.sendRedirect("/401");
            response.sendRedirect(request.getContextPath()+"/403.jsp");
//            response.sendRedirect("/403.jsp");
            return false;
        }
    }
}
